package create;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

class MyCallable implements Callable<Long> {

    @Override
    public Long call() throws Exception {
        long result=0;
        for(int i=1;i<=100;i++){
            result += i;
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
}
public class CallableDemo {

    public static void main(String[] args)throws Exception {
        FutureTask<Long> task = new FutureTask(new MyCallable());
        Thread th = new Thread(task);

        th.start();
        long result = task.get();
        System.out.println("result=" + result);
    }
}
